package com.zxw.user.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zxw.common.web.annotation.InitSelectInfo;
import com.zxw.user.api.RoleAPI;
import com.zxw.common.core.base.res.BaseRes;
import com.zxw.user.domain.dto.RoleDTO;
import com.zxw.user.domain.entity.Role;
import com.zxw.user.domain.vo.RolePageVO;
import com.zxw.user.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Xuewei.Zhang
 * @since 2022-01-21
 */
@Api(tags = "角色模块")
@RestController
@RequestMapping("/role")
@RequiredArgsConstructor
public class RoleController implements RoleAPI {

    private final RoleService roleService;

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("根据主键获取角色")
    @ApiImplicitParam(name = "id", value = "主键id Long : 格式 1,2,3 ", required = true)
    @GetMapping("/select/{id}")
    public BaseRes<Role> findRoleById(@PathVariable("id") Long id) {
        Role role = roleService.findRoleById(id);
        return BaseRes.ok(role);
    }


    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("获取公司角色列表")
    @GetMapping("/role-list")
    public BaseRes<List<RoleDTO>> roleList(RolePageVO rolePageVO) {
        List<RoleDTO> roleList = roleService.roleList(rolePageVO);
        return BaseRes.ok(roleList);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("获取公司角色列表")
    @GetMapping("/role-list-page")
    public BaseRes<IPage<RoleDTO>> roleListPage(RolePageVO rolePageVO) {
        IPage<RoleDTO> roleList = roleService.roleListPage(rolePageVO);
        return BaseRes.okPage(roleList);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("添加角色")
    @PostMapping("/add-role")
    public BaseRes<Role> addRole(@RequestBody Role role) {
        roleService.addRole(role);
        return BaseRes.ok(role);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("更新角色")
    @PutMapping("/update/{id}")
    public BaseRes<Role> update(@RequestBody Role role) {
        roleService.update(role);
        return BaseRes.ok(role);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("删除角色")
    @DeleteMapping("/delete-role/{ids}")
    public BaseRes deleteButton(@PathVariable("ids") String ids) {
        roleService.delete(ids);
        return BaseRes.ok();
    }

}
